/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp.junit;

/**
 *
 * @author marius
 */
public class MoneyOps {

	public static MoneyFactory mf = MoneyFactory.getDefaultFactory();

	public static Money simpleAdd(Money m1, Money m2) throws IncompatibleCurrencyException, UnexistingCurrencyException
	{
		if (m1.getCurrency() == null)
			throw new UnexistingCurrencyException(m1.getCurrency());
		if (m2.getCurrency() == null)
			throw new UnexistingCurrencyException(m2.getCurrency());

		if (m1.getCurrency().equals(m2.getCurrency())) { 
			Money m=mf.createMoney(m1.getValue()+m2.getValue(),m1.getCurrency());
			return m;
		}

		throw new IncompatibleCurrencyException(m1.getCurrency(), m2.getCurrency());
	}
}
